//
//  SwipeFromViewController.m
//  AnimationDemo
//
//  Created by Jiaozl 2018 on 2018/9/14.
//  Copyright © 2018年 Jiaozl. All rights reserved.
//

#import "SwipeFromViewController.h"
#import "SwipeToViewController.h"

@interface SwipeFromViewController ()
@end

@implementation SwipeFromViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setupGesture];
}

- (void)setupGesture
{
    // 添加屏幕边缘滑动手势
    UIScreenEdgePanGestureRecognizer *screenEdgePanGR = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(__actionLeftSwipe:)];
    // 响应右边的滑动事件
    screenEdgePanGR.edges = UIRectEdgeRight;
    [self.view addGestureRecognizer:screenEdgePanGR];
}

// MARK: - action
- (IBAction)gotoNextVC:(id)sender
{
    [self __actionPresentNewVC:sender];
}

- (void)__actionLeftSwipe:(UIScreenEdgePanGestureRecognizer *)sender
{
    [self __actionPresentNewVC:sender];
}

- (void)__actionPresentNewVC:(id)sender
{
    if ([sender isKindOfClass:UIGestureRecognizer.class] ) {
        if (((UIGestureRecognizer *)sender).state == UIGestureRecognizerStateBegan) {
            [self __createNewVC:sender];
        }
    } else {
        [self __createNewVC:sender];
    }
}

- (void)__createNewVC:(id)sender
{
    SwipeToViewController *toVC = [[SwipeToViewController alloc] init];
    if ([sender isKindOfClass:UIGestureRecognizer.class] ) {
        toVC.gesture = sender;
    } else {
        toVC.gesture = nil;
    }
    [self presentViewController:toVC animated:YES completion:nil];
}
@end
